import { Message } from 'element-ui'

let flag = null

const resetMessage = (options) => {
  if (flag) flag.close()
  flag = Message(options)
}

const messageType = ['success', 'error', 'warning', 'info']

messageType.forEach(type => {
  resetMessage[type] = options => {
    if (typeof options === 'string') options = { message: options }
    options.type = type
    return resetMessage(options)
  }
})

export const myMessage = resetMessage
